#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int read() {
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9') {
        if(ch=='-') f*=-1;
        ch=getchar();
    }
    while(ch<='9' && ch>='0') {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int n,T;
int a[200005],pos[1000002],lst[200005],ans,c[200005],l1,l2;
ll dp[200005][2];
inline void dfs(int x,int sum) {
    if(x>n) {
        ans=max(ans,sum);
        return ;
    }
    int tmp=l1;
    l1=x;
    if(a[tmp]==a[x]) dfs(x+1,sum+a[x]);
    else dfs(x+1,sum);
    l1=tmp;
    tmp=l2;
    l2=x;
    if(a[tmp]==a[x]) dfs(x+1,sum+a[x]);
    else dfs(x+1,sum);
    l2=tmp;
    return ;
}
int main() {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    T=read();
    while(T--) {
        n=read();
        if(n<=100) {
            for(int i=1;i<=n;++i) a[i]=read();
            ans=0;
            l1=l2=0;
            dfs(1,0);
            cout<<ans<<endl;
        }
        else if(n<=2000){
            for(int i=1;i<=n;++i) a[i]=read();
            cout<<ans<<endl;
        }
        else {
            for(int i=1;i<=n;++i) a[i]=read();
            cout<<ans<<endl;
        }
    }
    return 0;
}